package com.smxy.daydayup.controller;

import com.smxy.daydayup.service.UserService;
import com.smxy.daydayup.util.number.EncryptionUtil;
import com.smxy.daydayup.util.number.VerifyCodeUtil;
import com.smxy.daydayup.util.result.ResultUtil;
import com.smxy.daydayup.util.result.ReturnResult;
import com.smxy.daydayup.util.result.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSendException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @team daydayup
 * @time 2021-12-07 16:11
 */
@Api(tags = "用户信息效验控制器")
@RestController
@RequestMapping("/check")
public class UserCheckController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "效验学号接口")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "userNumber",
                    value = "学号/工号",
                    required = true,
                    dataTypeClass = String.class
            ),
            @ApiImplicitParam(
                    name = "userNumber",
                    value = "学校id",
                    required = true,
                    dataTypeClass = Long.class
            )
    })
    @PostMapping("/number")
    public ReturnResult checkNumber(@RequestParam("userNumber") String userNumber,
                                    @RequestParam("schoolId") Long schoolId){
        if(userService.checkNumber(userNumber,schoolId)>0){
            return ResultUtil.returnFail(StatusCode.SAME_FAIL,"同名数据冲突");
        }else{
            return ResultUtil.returnSuccess();
        }
    }
    @ApiOperation(value = "效验手机号接口")
    @ApiImplicitParam(
            name = "userTel",
            value = "手机号",
            required = true,
            dataTypeClass = String.class
    )
    @PostMapping("/tel")
    public ReturnResult checkTel(@RequestParam("userTel") String userTel){
        if(userService.checkTel(userTel)>0){
            return ResultUtil.returnFail(StatusCode.SAME_FAIL,"同名数据冲突");
        }else{
            return ResultUtil.returnSuccess();
        }
    }
    @ApiOperation(value = "效验邮箱的接口")
    @ApiImplicitParam(
            name = "userEmail",
            value = "邮箱",
            required = true,
            dataTypeClass = String.class
    )
    @PostMapping("/email")
    public ReturnResult checkEmail(@RequestParam("userEmail") String userEmail){
        if(userService.checkEmail(userEmail)>0){
            return ResultUtil.returnFail(StatusCode.SAME_FAIL,"同名数据冲突");
        }else{
            return ResultUtil.returnSuccess();
        }
    }


}
